-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.cpp
More file actions
31 lines (24 loc) · 739 Bytes
/
Solution.cpp
File metadata and controls
31 lines (24 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>
using namespace std;
int longestIncreasingSubsequence(vector<int>& arr) {
int n = arr.size();
vector<int> lis(n, 1);
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++)
if (arr[i] > arr[j] && lis[i] < lis[j] + 1)
lis[i] = lis[j] + 1;
return *max_element(lis.begin(), lis.end());
}
int main() {
int n;
cout << "Enter the number of elements: ";
cin >> n;
vector<int> arr(n);
cout << "Enter the elements of the array:\n";
for (int i = 0; i < n; i++)
cin >> arr[i];
int result = longestIncreasingSubsequence(arr);
cout << "Length of Longest Increasing Subsequence: " << result << endl;
return 0;
}